-
Notifications
You must be signed in to change notification settings - Fork 793
Fix for issue - #2808: Invalid type WSGIRequest for attribute 'request' value opentelemetry #3731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py
Outdated
Show resolved
Hide resolved
...nstrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py
Outdated
Show resolved
Hide resolved
...nstrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again @rads-1996 , this lgtm. Maintainers will also have a look.
Thank you so much. Really appreciate the review :) |
...nstrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py
Outdated
Show resolved
Hide resolved
...nstrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py
Outdated
Show resolved
Hide resolved
...nstrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py
Outdated
Show resolved
Hide resolved
…y-python-contrib into django-issue-fix
…y-python-contrib into django-issue-fix
ec091ea
to
27498de
Compare
…y-python-contrib into django-issue-fix
for _, value_list in attributes.items(): | ||
for index, value in enumerate(value_list): | ||
if isinstance(value, HttpRequest): | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't str(value) enough instead of poking with HttpRequest internals?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xrmx Fixed the logic.
c9b002b
to
d7f1ce0
Compare
9784d0a
to
08e817c
Compare
0bce4fd
to
c79c917
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the research and the PR, but I'm not sure if the issue is fixed. I'm still able to reproduce it, because Django logging extension (django.request
and django.server
) is still adding request to extras
, which causes logs to be emitted with a request attribute containing an invalid value (WSGIRequest).
I didn't dig into it in detail, but what I imagine can solve the issue is to use a logging filter like:
class RequestFilter(logging.Filter):
def filter(self, record: logging.LogRecord) -> bool:
request = getattr(record, "request", None)
record.request = str(request)
return True
logger = logging.getLogger("django.request")
logger.addFilter(RequestFilter())
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes #2808
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.